//package com.lebang.schedule;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.lebang.component.RedisClient;
//import com.lebang.model.NewsPage;
//import com.lebang.service.NewsDetailService;
//import com.lebang.service.earn.AppEarnLookService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.RandomUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
///**
// * @Author: hwq
// * @Date: 2019/10/9 15:46
// * @Version 1.0
// */
//@Slf4j
//@Component
//public class NewsTask {
//    @Autowired
//    private RedisClient redisClient;
//    @Autowired
//    private NewsDetailService newsDetailService;
//    @Autowired
//    private AppEarnLookService appEarnLookService;
//    private static String PAGE = "0";
//
//    @Value("${info.is-cences}")
//    private Boolean isStar;
//
//    /**
//     * 每日3点统计数据
//     */
//    @Scheduled(cron = "0/3 * * * * ? ")
//    public void execute() {
//
////        if(redisClient.tryGetDistributedLock("lock:NewsTask:census", UUIDUtil.M(),100000)) {
//        String str = "[{\n" +
//                "\t\t\"value\": \"推荐\",\n" +
//                "\t\t\"key\": \"__all__\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"社会\",\n" +
//                "\t\t\"key\": \"news_society\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"娱乐\",\n" +
//                "\t\t\"key\": \"news_entertainment\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"科技\",\n" +
//                "\t\t\"key\": \"news_tech\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"汽车\",\n" +
//                "\t\t\"key\": \"news_car\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"体育\",\n" +
//                "\t\t\"key\": \"news_sports\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"财经\",\n" +
//                "\t\t\"key\": \"news_finance\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"军事\",\n" +
//                "\t\t\"key\": \"news_military\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"国际\",\n" +
//                "\t\t\"key\": \"news_world\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"健康\",\n" +
//                "\t\t\"key\": \"news_health\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"正能量\",\n" +
//                "\t\t\"key\": \"positive\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"房产\",\n" +
//                "\t\t\"key\": \"news_house\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"时尚\",\n" +
//                "\t\t\"key\": \"news_fashion\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"育儿\",\n" +
//                "\t\t\"key\": \"news_baby\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"历史\",\n" +
//                "\t\t\"key\": \"news_history\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"搞笑\",\n" +
//                "\t\t\"key\": \"funny\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"数码\",\n" +
//                "\t\t\"key\": \"digital\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"美食\",\n" +
//                "\t\t\"key\": \"news_food\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"养生\",\n" +
//                "\t\t\"key\": \"news_regimen\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"电影\",\n" +
//                "\t\t\"key\": \"movie\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"手机\",\n" +
//                "\t\t\"key\": \"cellphone\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"旅游\",\n" +
//                "\t\t\"key\": \"news_travel\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"情感\",\n" +
//                "\t\t\"key\": \"emotion\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"家居\",\n" +
//                "\t\t\"key\": \"news_home\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"教育\",\n" +
//                "\t\t\"key\": \"news_edu\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"三农\",\n" +
//                "\t\t\"key\": \"news_agriculture\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"孕产\",\n" +
//                "\t\t\"key\": \"pregnancy\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"文化\",\n" +
//                "\t\t\"key\": \"news_culture\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"游戏\",\n" +
//                "\t\t\"key\": \"news_game\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"股票\",\n" +
//                "\t\t\"key\": \"stock\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"科学\",\n" +
//                "\t\t\"key\": \"science_all\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"动漫\",\n" +
//                "\t\t\"key\": \"news_comic\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"故事\",\n" +
//                "\t\t\"key\": \"news_story\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"收藏\",\n" +
//                "\t\t\"key\": \"news_collect\"\n" +
//                "\t}, {\n" +
//                "\t\t\"value\": \"星座\",\n" +
//                "\t\t\"key\": \"news_astrology\"\n" +
//                "\t}]";
//        JSONArray array = JSON.parseArray(str);
//        int k = RandomUtils.nextInt(0, array.size());
//        JSONObject job = array.getJSONObject(k);
//
//        String page = "0";
//        for (int i = 0; i < 2; i++) {
//            try {
//                // Thread.sleep(1000);
//                page = redisClient.get("newskey:" + job.getString("key"));
//                if (page == null) {
//                    page = "0";
//                }
//                NewsPage newsPage = appEarnLookService.getNewSByKey("", page, job.getString("key"));
//                if (newsPage == null) {
//                        page = "0";
//                        continue;
//
//                }
//                if(newsPage.getData()==null||newsPage.getData().size()==0){
//                    page = "0";
//                    continue;
//                }
//                page = newsPage.getPage();
//                redisClient.set("newskey:" + job.getString("key"), page);
//                newsPage.getData().forEach(s -> {
//                    if (newsDetailService.selectByItemId(s.getItem_id()) == 0) {
//                        newsDetailService.insert(s);
//                    } else {
//                        log.info(s.getItem_id() + "已存在");
//                    }
//                });
//            } catch (Exception e) {
//                e.printStackTrace();
//                continue;
//            }
//            System.out.println(i);
//        }
//
//        log.info("统计完成...");
//    }
//
//
//    /**
//     * 每日3点统计数据
//     */
//    @Scheduled(cron = "0 0/1 * * * ? ")
//    public void execute1() {
//
////        if(redisClient.tryGetDistributedLock("lock:NewsTask:census", UUIDUtil.M(),100000)) {
//
//
//        String page = "0";
//        for (int i = 0; i < 3; i++) {
//            try {
//                // Thread.sleep(1000);
//                page = redisClient.get("newskey:" + "__all__");
//                if (page == null) {
//                    page = "0";
//                }
//                NewsPage newsPage = appEarnLookService.getNewSByKey("", page, "__all__");
//                if (newsPage == null) {
//                    page = "0";
//                    continue;
//
//                }
//                if(newsPage.getData()==null||newsPage.getData().size()==0){
//                    page = "0";
//                    continue;
//                }
//                page = newsPage.getPage();
//                redisClient.set("newskey:" + "__all__", page);
//                newsPage.getData().forEach(s -> {
//                    if (newsDetailService.selectByItemId(s.getItem_id()) == 0) {
//                        newsDetailService.insert(s);
//                    } else {
//                        log.info(s.getItem_id() + "已存在");
//                    }
//                });
//            } catch (Exception e) {
//                e.printStackTrace();
//                continue;
//            }
//            System.out.println(i);
//        }
//
//        log.info("统计完成...");
//    }
//}
